<template>
  <header class="header">
    <h1>todos</h1>
    <input v-model="isDone" id="toggle-all" class="toggle-all" type="checkbox" >
    <label for="toggle-all"></label>
    <input
      class="new-todo"
      placeholder="输入任务名称-回车确认"
      autofocus
      v-model="str"
      @keyup.enter="addList"
    />
  </header>
</template>

<script>
import {mapState, mapMutations} from 'vuex'
export default {
  data(){
    return {
       str:''
    }
  },
  methods:{
    ...mapMutations(['setMyList','cahnegFilterIsDone']),
    addList(){
      if(this.str.trim() !== ''){
        this.setMyList({
          id:this.$store.state.myList[this.$store.state.myList.length-1].id++,
          name: this.str,
          isDone:false
        })
        this.str =''
      }
    }
  },
  computed:{
    ...mapState(['myList']),
    isDone:{
      set(val){
        this.cahnegFilterIsDone(val)
      },
      get(){
        return this.myList. every(item => item.isDone)
      }
    }
  }

}
</script>